import java.util.Scanner;

public class java7 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入一个十进制数：");
        int decimalNumber = scanner.nextInt();

        String binaryNumber = decimalToBinary(decimalNumber);
        System.out.println("转换为二进制数为：" + binaryNumber);
    }

    public static String decimalToBinary(int decimalNumber) {
        if (decimalNumber == 0) {
            return "0";
        }

        StringBuilder binary = new StringBuilder();
        while (decimalNumber > 0) {
            int remainder = decimalNumber % 2;
            binary.insert(0, remainder); // 在最前面插入余数
            decimalNumber = decimalNumber / 2;
        }

        return binary.toString();
    }
}
